//
//  DTDeviceBase.m
//  PersonalManager
//
//  Created by user on 16/8/1.
//  Copyright © 2016年 Haiyun.Qian. All rights reserved.
//

#import "DTDeviceBase.h"
#import <SystemConfiguration/CaptiveNetwork.h>
@interface DTDeviceBase()<UIAlertViewDelegate>
@end
@implementation DTDeviceBase


-(instancetype)init{
    self = [super init];
    return self;
}

-(void)getUUID:(DTJavascriptCommand *)command {
    NSUUID *uuid = [[NSUUID alloc ]init];
    NSString *uuidString = uuid.UUIDString;
    NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys: uuidString,@"uuid", nil];
    [command successRessponse:dic];
    
}
/*
- (id)fetchSSIDInfo {
    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces;
    
    NSLog(@"Supported interfaces: %@", ifs);
    id info = nil;
    for (NSString *ifnam in ifs)
    {
        info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        NSLog(@"%@ => %@", ifnam, info);
        if (info && [info count])
        {
            break;
        }
    }
    return info;
}*/

-(void)getInterface:(DTJavascriptCommand *)command {
    
    //实现代码
    NSString *ssid = @"Not Found";
    NSString *macIp = @"Not Found";
    CFArrayRef myArray = CNCopySupportedInterfaces();
    if (myArray != nil) {
        CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
        if (myDict != nil) {
            NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
            
            ssid = [dict valueForKey:@"SSID"];
            macIp = [dict valueForKey:@"BSSID"];
        }
    }
    UIAlertView *av = [[UIAlertView alloc] initWithTitle:ssid
                                                 message:macIp
                                                delegate:self
                                       cancelButtonTitle:nil
                                       otherButtonTitles:@"OK", nil];
    [av show];
    self.command = command;

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
//    NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:@"getInterface",@"", nil];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%ld",(long)buttonIndex],@"点击了alertview", nil];
    [_command successRessponse:dic];

}

@end
